package com.sg.hms.ServiceImpl;

import com.sg.hms.Dao.H_MoneyAppliDao;
import com.sg.hms.Dao.H_SearchApplicationDao;
import com.sg.hms.DaoImpl.H_MoneyAppliDaoImpl;
import com.sg.hms.DaoImpl.H_SearchApplicationDaoImpl;
import com.sg.hms.Service.H_ApplicationService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class H_ApplicationServiceImpl implements H_ApplicationService{
    private H_SearchApplicationDao haDao=new H_SearchApplicationDaoImpl(); 
    private H_MoneyAppliDao mdao=new H_MoneyAppliDaoImpl();
	@Override
	public JSONObject searchapplication(int start,int pagesize,String state) {
		// TODO Auto-generated method stub
		JSONObject json=new JSONObject();
		JSONArray jsonArray=JSONArray.fromObject(haDao.searchapplication(start, pagesize,state));
		json.put("total", haDao.getapplicationcount(state));
		json.put("rows", jsonArray);
		return json;
	}
	@Override
	public JSONObject searchapplication(int start, int pagesize, String d,String state) {
		// TODO Auto-generated method stub
		JSONObject json=new JSONObject();
		JSONArray jsonArray=JSONArray.fromObject(haDao.searchapplication(start, pagesize, d,state));
		json.put("total", haDao.getapplicationcount(d,state));
		json.put("rows", jsonArray);
		return json;
	}
	@Override
	public int creatMoneyApplication(int elId, int aId, double money) {
		// TODO Auto-generated method stub
		return haDao.creatMoneyApplication(elId, aId, money);
	}
	@Override
	public int updateH_Application(int aId) {
		// TODO Auto-generated method stub
		return haDao.updateApplication(aId, "未通过", "无条件直接退回...");
	}
	@Override
	public JSONObject searchmoneyapplication(int start, int pagesize,String maState) {
		// TODO Auto-generated method stub
		JSONObject json=new JSONObject();
		JSONArray jsonArray=JSONArray.fromObject(haDao.searchmoneyapplication(start, pagesize,maState));
		json.put("total", haDao.getmoneyapplicationcount(maState));
		json.put("rows", jsonArray);
		return json;
	}
	@Override
	public JSONObject searchmoneyapplication(int start, int pagesize, String madate,String maState) {
		// TODO Auto-generated method stub
		JSONObject json=new JSONObject();
		JSONArray jsonArray=JSONArray.fromObject(haDao.searchmoneyapplication(start, pagesize, madate,maState));
		json.put("total", haDao.getmoneyapplicationcount(madate,maState));
		json.put("rows", jsonArray);
		return json;
	}
	@Override
	public int replyApplication(int maId,int aId, String state, String note) {
		// TODO Auto-generated method stub
		int flag=0;
		if(haDao.updateApplication(aId, state, note)==1){
			flag=mdao.updateMoneyAppliState("已回复", maId);
		}
		return flag;
	}


}
